package com.tanhua.manager.exception;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(Exception.class)
    public ResponseEntity handlerException(Exception e) {
        e.printStackTrace();
        String message = "网络繁忙~~~";
        if (e instanceof BusinessException) {
            message = e.getMessage();
        }

        Map<String, String> errorResult = new HashMap<>();
        errorResult.put("message", message);
        return ResponseEntity.status(500).body(errorResult);
    }
}
